package com.ruoyi.web.controller.adopt;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.adopt.domain.ApplyRecord;
import com.ruoyi.adopt.service.IApplyRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 记录Controller
 *
 * @author shilling
 * @date 2022-04-08
 */
@RestController
@RequestMapping("/adopt/record")
public class ApplyRecordController extends BaseController
{
    @Autowired
    private IApplyRecordService applyRecordService;

    /**
     * 查询记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ApplyRecord applyRecord)
    {
        startPage();
        List<ApplyRecord> list = applyRecordService.selectApplyRecordList(applyRecord);
        return getDataTable(list);
    }

    /**
     * 导出记录列表
     */
    @Log(title = "记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ApplyRecord applyRecord)
    {
        List<ApplyRecord> list = applyRecordService.selectApplyRecordList(applyRecord);
        ExcelUtil<ApplyRecord> util = new ExcelUtil<ApplyRecord>(ApplyRecord.class);
        util.exportExcel(response, list, "记录数据");
    }

    /**
     * 获取记录详细信息
     */
    @GetMapping(value = "/{applyRecordId}")
    public AjaxResult getInfo(@PathVariable("applyRecordId") Long applyRecordId)
    {
        return AjaxResult.success(applyRecordService.selectApplyRecordByApplyRecordId(applyRecordId));
    }

    /**
     * 新增记录
     */
    @Log(title = "记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ApplyRecord applyRecord)
    {
        return toAjax(applyRecordService.insertApplyRecord(applyRecord));
    }

    /**
     * 修改记录
     */
    @Log(title = "记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ApplyRecord applyRecord)
    {
        return toAjax(applyRecordService.updateApplyRecord(applyRecord));
    }

    /**
     * 删除记录
     */
    @Log(title = "记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{applyRecordIds}")
    public AjaxResult remove(@PathVariable Long[] applyRecordIds)
    {
        return toAjax(applyRecordService.deleteApplyRecordByApplyRecordIds(applyRecordIds));
    }
}
